# -*- coding: utf-8 -*-
from django.http import HttpResponseRedirect
from django.http import HttpResponse
from django.shortcuts import render_to_response, redirect
from django.template import RequestContext
from django.contrib.auth.decorators import login_required
from django.core.urlresolvers import reverse
from django.conf import settings

from apps.perfil.models import Empresario
from apps.perfil.forms import EditProfileForm
from apps.l10n.models import Country, AdminArea, City
################################################################################
@login_required
def edit_profile(request, form_class=EditProfileForm):
    usuario = request.user
    empresario = Empresario.objects.get(user=usuario)
    depto = empresario.departamento.id
    ciudad = empresario.ciudad.id    
    if request.method == 'POST':
        form = form_class(request.POST)        
        if form.is_valid():            
            form.save(usuario)            
            return HttpResponseRedirect(reverse('edit_account'))
    else:
        form = form_class()
        form.datos_usuario(empresario)
    return render_to_response("registration/edit_profile.html",
                              { 'form' : form , 'depto' : depto, 'ciudad' : ciudad},
                                context_instance=RequestContext(request))
################################################################################